import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

//静态路由配置
void main() => runApp(const MyApp3());

//定义根目录Widget
class MyApp3 extends StatelessWidget {
  const MyApp3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        //初始化默认的 Material 组件本地化
        GlobalMaterialLocalizations.delegate,
        //初始化默认的 通用 Widget 组件本地化
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      //当前区域，如果为null则使用系统区域一般用于语言切换
      //传入两个参数，语言代码，国家代码
      //这里配制为中国
      locale: const Locale('zh', 'CN'),
      //定义当前应用程序所支持的语言环境
      supportedLocales: const [
        Locale('en', 'US'), // English 英文
        Locale('zh', 'CN'), // 中文
      ],
      routes: {
        //默认页面
        "/": (BuildContext context) => const Exam218HomePage(),
      },
    );
  }
}

///代码路径 lib/code2/code219_Button.dart
class Exam218HomePage extends StatefulWidget {
  const Exam218HomePage({Key? key}) : super(key: key);

  @override
  State<Exam218HomePage> createState() => _Exam218HomePageState();
}

class _Exam218HomePageState extends State<Exam218HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //页面的头部
      appBar: AppBar(title: const Text("标题")),
      //页面的主内容区
      body: Container(
        width: double.infinity,
        //竖直方向排开子Widget
        child: Column(
          children: [
            const SizedBox(
              height: 44,
            ),
            TextButton(
              child: const Text("ElevatedButton 按钮"),
              onPressed: () {
                //点击事件
              },
            ),
            const SizedBox(
              height: 44,
            ),
            ElevatedButton(
              child: const Text("ElevatedButton 按钮"),
              onPressed: () {
                //点击 事件
              },
            )
          ],
        ),
      ),
    );
  }
  ///代码清单2-22 ButtonStyle 样式
  ///代码路径 lib/code2/code219_Button.dart
  ButtonStyle buileButtonStyle() {
    return ButtonStyle(
      //定义文本的样式 这里设置的颜色是不起作用的
      textStyle:
          MaterialStateProperty.all(TextStyle(fontSize: 18, color: Colors.red)),
      //设置按钮上字体与图标的颜色
      //foregroundColor: MaterialStateProperty.all(Colors.deepPurple),
      //更优美的方式来设置
      foregroundColor: MaterialStateProperty.resolveWith(
        (states) {
          if (states.contains(MaterialState.focused) &&
              !states.contains(MaterialState.pressed)) {
            //获取焦点时的颜色
            return Colors.blue;
          } else if (states.contains(MaterialState.pressed)) {
            //按下时的颜色
            return Colors.deepPurple;
          }
          //默认状态使用灰色
          return Colors.grey;
        },
      ),
      //背景颜色
      backgroundColor: MaterialStateProperty.resolveWith((states) {
        //设置按下时的背景颜色
        if (states.contains(MaterialState.pressed)) {
          return Colors.blue[200];
        }
        //默认不使用背景颜色
        return null;
      }),
      //设置水波纹颜色
      overlayColor: MaterialStateProperty.all(Colors.yellow),
      //设置阴影  不适用于这里的TextButton
      elevation: MaterialStateProperty.all(0),
      //设置按钮内边距
      padding: MaterialStateProperty.all(EdgeInsets.all(10)),
      //设置按钮的大小
      minimumSize: MaterialStateProperty.all(Size(200, 100)),

      //设置边框
      side: MaterialStateProperty.all(BorderSide(color: Colors.grey, width: 1)),
      //外边框装饰 会覆盖 side 配置的样式
      shape: MaterialStateProperty.all(StadiumBorder()),
    );
  }
}
